package com.aku.controller;

import com.aku.entity.Door;
import com.aku.service.DoorService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DoorController {

    @Resource
    private DoorService doorService;

    @RequestMapping("/doorList")
    public String findAllDoor(Model model){
        List<Door> doors = doorService.findAllDoor();
        model.addAttribute("doors",doors);
        return "door_list";
    }

    @RequestMapping("/doorAdd")
    public String doorAdd(Door door){
        doorService.addDoor(door);
        return "redirect:/doorList";
    }

    @RequestMapping("/doorInfo")
    public String doorAdd(Integer id,Model model){
        Door door = doorService.findDoorById(id);
        model.addAttribute("door",door);
        return "door_update";
}

    @RequestMapping("/doorUpdate")
    public String doorUpdate(Door door){
        doorService.updateDoor(door);
        return "redirect:/doorList";
    }

    @RequestMapping("/doorDelete")
    public String doorDelete(Integer id){
        doorService.removeDoorById(id);
        return "redirect:/doorList";
    }


}
